############################################
# Media Measurement Matters                #
# Replication Code                         #
# Appendix - Experimental Ests. (App. I-K) #
############################################

# The following file contains code for replicating the experimental analyses in the
# supplemental appendix. These results are reported in Appendices I, J, and K in
# the online supplement.

# Set-Up ----

# If desired, set up path into which to save plots and tables
plot_path <- NULL
table_path <- NULL

# Load packages
library(tidyverse)
library(ggpubr)
library(estimatr)
library(xtable)
library(stargazer)
library(gtools)

# Set up helper operations
`%notin%` <- Negate(`%in%`)

# Set up colors
red_mit = '#A31F34'
red_light = '#A9606C'
blue_mit = '#315485'
grey_light= '#C2C0BF'
grey_dark = '#8A8B8C'
black = '#353132'

# Source helper functions
source("helper_functions.R")

# > Read in data ----

# Read in survey data
srvy <- read_rds("data/survey_data_cleaned.rds")

# Read in web data and remove portal sites
web <- read_rds("data/web_use.rds")

# Filter out portal sites
web_noport <- web %>% 
  filter(domain_recode %notin% c("aol.com", "msn.com", "google.com"))

# Appendix I: Treatment Effects and Average Ratings ----

# > Unconditional average treatment effects ----

# Set theme for plotting
theme_set(theme_bw() + 
            theme(legend.position = "bottom",
                  plot.title = element_text(hjust = 0.5, face = "bold",size = 16),
                  plot.subtitle = element_text(hjust = 0.5, face = "italic", size = 12),
                  axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),
                                              face = "bold", size = 12, angle = 0, hjust = 0.5),
                  axis.title.y = element_text(margin = unit(c(0, 3, 0, 0), "mm"), 
                                              face = "bold", size = 12),
                  legend.title = element_text(face = "bold", hjust = 0.5, size = 12),
                  legend.text = element_text(hjust = 0.5, size = 10),
                  axis.text.y = element_text(size = 10, color = "black"),
                  axis.text.x = element_text(size = 10, color = "black"),
                  legend.box = "vertical",
                  legend.background = element_blank(),
                  legend.box.background = element_rect(colour = "black"),
                  text=element_text(colour=black, 
                                    size=15)))

# Estimate ATEs for each comparison (partisan media vs. entertainment, Fox vs. MSNBC)
overall_results <- overall_plot(weights = FALSE)

# Figure I1: plot unconditional ATEs for each comparison, outcome
(i1 <- ggplot(na.omit(overall_results), 
                        aes(x=factor(id, levels = c("Fox vs.\nEntertainment",
                                                    "MSNBC vs.\nEntertainment",
                                                    "Fox vs.\nMSNBC")),
                            col = factor(id, levels = c("Fox vs.\nEntertainment",
                                                        "MSNBC vs.\nEntertainment",
                                                        "Fox vs.\nMSNBC")),
                            shape = factor(id, levels = c("Fox vs.\nEntertainment",
                                                          "MSNBC vs.\nEntertainment",
                                                          "Fox vs.\nMSNBC")))) +
    geom_hline(yintercept=0, col = "white") +
    geom_hline(yintercept=0, linetype="dashed", col = grey_dark) +
    geom_errorbar(aes(ymin=min_cilo, ymax=max_cihi),width=0) +
    geom_errorbar(aes(ymin=min_cilo90, ymax=max_cihi90),width=0, lwd = 1) +
    geom_point(aes(y=naive),
               position = position_dodge(width = 0.5),
               size = 2.5) +
    facet_wrap(~ outcome,nrow=1) +
    xlab("Comparison Across Conditions") +
    ylab("Average Treatment Effect") +
    scale_y_continuous(breaks=seq(-0.2,0.2,0.1),
                       labels=plot_labels()$att,
                       limits = c(-0.235, 0.235),
                       sec.axis = dup_axis(name="",
                                           breaks=seq(-0.2,0.2,0.1),
                                           labels = plot_labels()$share)) +
    scale_colour_manual("Comparison",values=c(red_mit, blue_mit, black)) +
    scale_shape_manual("Comparison",values=c(16, 17, 15)) +
    guides(color = "none", shape = "none"))

ggsave(i1, path = plot_path, filename = "fig_i1.pdf", 
       width=9, height=5, dpi = 600)

# > Average ratings by experimental condition ----

# Create labels for plots
consump_labels3 <- gen_ranges(bin_var = "news_consump_bin3", score_version = "news_consump",
                              parentheses = TRUE)
consump_labels3 <- paste0(c("Low News\nConsumption\n", "Medium News\nConsumption\n", 
                            "High News\nConsumption\n"), 
                          consump_labels3)

code_labels <- gen_ranges(bin_var = "score_code", score_version = "score_noportals",
                          parentheses = TRUE)
code_labels <- paste(c("More Liberal\nThan CNN\n", "Between CNN\nand Yahoo!\n", 
                       "More Conserv.\nThan Yahoo!\n"), 
                     code_labels, sep = "")

code_labels_hard <- gen_ranges(bin_var = "score_code_hard", score_version = "score_hard",
                               parentheses = TRUE)
code_labels_hard <- paste(c("More Liberal\nThan CNN\n", "Between CNN\nand Yahoo!\n", 
                            "More Conserv.\nThan Yahoo!\n"), 
                          code_labels_hard, sep = "")

# Figure I2: average ratings by relative volume
i2 <- avg_plot(group_var = "news_consump_bin3", 
               x_title = "Relative Volume of News vs. Non-News",
               x_labels = consump_labels3)
ggsave(i2, path = plot_path, filename = "fig_i2.pdf",
       dpi = 600, width=9, height=5.5)

# Figure I3(a): average ratings by relative slant (all URL visits)
i3_a <- avg_plot(group_var = "score_code", 
                 x_title = "Relative Slant of News Consumption",
                 x_labels = code_labels)
ggsave(i3_a, path = plot_path, filename = "fig_i3_a.pdf",
       dpi = 600, width=9, height=5.5)

# Figure I3(b): average ratings by relative slant (hard news only)
i3_b <- avg_plot(group_var = "score_code_hard", 
                 x_title = "Relative Slant of News Consumption (Hard News Only)",
                 x_labels = code_labels_hard)
ggsave(i3_b, path = plot_path, filename = "fig_i3_b.pdf",
       dpi = 600, width=9, height=5.5)

# Figure I4: average ratings by stated media preferences
i4 <- avg_plot(group_var = "med_pref_num", 
               x_title = "Stated Media Preference",
               x_labels = c("Prefer\nMSNBC", "Prefer\nEntertainment",
                            "Prefer\nFox"))
ggsave(i4, path = plot_path, filename = "fig_i4.pdf",
       dpi = 600, width=9, height=5.5)

# Appendix J: Comparing Exposure to Fox versus MSNBC ----

# > Figure J1: Effects by relative volume ----

# Estimate ATEs within each preference group
consump_3_fx <- map(1:3, function(x){
  fox_plot(var = "news_consump_bin3", 
           pref_val = x, labels = consump_labels3)
}) %>% bind_rows()

# Plot results
(j1 <- ggplot(na.omit(consump_3_fx), 
                                  aes(x=factor(val), colour=result)) +
    geom_hline(yintercept=0, color = "white") +
    geom_hline(yintercept=0, linetype="dashed", color = grey_dark) +
    geom_errorbar(aes(ymin=min_cilo90, ymax=max_cihi90, colour="naive"),
                  width=0, lwd = 1) +
    geom_errorbar(aes(ymin=min_cilo, ymax=max_cihi, colour="naive"),
                  width=0) +
    geom_point(aes(y=naive, colour="naive"), size = 2) +
    facet_wrap(~ outcome,nrow=1) +
    xlab("Relative Volume of News vs. Non-News") +
    scale_x_discrete(labels = unique(consump_3_fx$bin)) + 
    ylab("Average Treatment Effect of\nFox versus MSNBC") +
    scale_y_continuous(breaks=seq(-0.2,0.2,0.1),
                       labels=plot_labels()$att,
                       limits = c(-0.235, 0.235),
                       sec.axis = dup_axis(name="",
                                           breaks=seq(-0.2,0.2,0.1),
                                           labels = plot_labels()$share)) +
    scale_colour_manual(values=c(naive="black", bounds=red_mit),
                        guide="none") +
    theme(axis.text.x = element_text(size = 10, angle = 0, hjust = 0.5, color = "black")))

ggsave(j1, path = plot_path, filename = "fig_j1.pdf", 
       dpi = 600, width=9, height = 4.75)

# > Figure J2(a): Effects by relative slant (all URLs) ----

# Estimate ATEs within each preference group
score_code_fx <- map(1:3, function(x){
  fox_plot(var = "score_code", 
           pref_val = x, labels = code_labels)
}) %>% bind_rows()

# Plot results
(j2_a <- ggplot(na.omit(score_code_fx), 
                           aes(x=factor(val), colour=result)) +
    geom_hline(yintercept=0, color = "white") +
    geom_hline(yintercept=0, linetype="dashed", color = grey_dark) +
    geom_errorbar(aes(ymin=min_cilo90, ymax=max_cihi90, colour="naive"),
                  width=0, lwd = 1) +
    geom_errorbar(aes(ymin=min_cilo, ymax=max_cihi, colour="naive"),
                  width=0) +
    geom_point(aes(y=naive, colour="naive"),
               size = 2) +
    facet_wrap(~ outcome,nrow=1) +
    scale_x_discrete(labels = unique(score_code_fx$bin)) + 
    xlab("Relative Slant of News Consumption") +
    ylab("Average Treatment Effect\nof Fox vs. MSNBC") +
    scale_y_continuous(breaks=seq(-0.2,0.2,0.1),
                       labels=plot_labels()$att,
                       limits = c(-0.235, 0.235),
                       sec.axis = dup_axis(name="",
                                           breaks=seq(-0.2,0.2,0.1),
                                           labels = plot_labels()$share)) +
    scale_colour_manual(values=c(naive="black", bounds=red_mit),
                        guide="none") + 
    theme(axis.text.x = element_text(size = 10, angle = 0, hjust = 0.5, color = "black")))

ggsave(j2_a, path = plot_path, filename = "fig_j2_a.pdf", 
       width=9, height = 5, dpi = 600)

# > Figure J2(b): Effects by relative slant (hard news only) ----

# Estimate ATEs within each preference group
score_code_hard_fx <- map(1:3, function(x){
  fox_plot(var = "score_code_hard", 
           pref_val = x, labels = code_labels_hard)
}) %>% bind_rows()

# Plot results
(j2_b <- ggplot(na.omit(score_code_hard_fx), 
                                aes(x=factor(val), colour=result)) +
    geom_hline(yintercept=0, color = "white") +
    geom_hline(yintercept=0, linetype="dashed", color = grey_dark) +
    geom_errorbar(aes(ymin=min_cilo90, ymax=max_cihi90, colour="naive"),
                  width=0, lwd = 1) +
    geom_errorbar(aes(ymin=min_cilo, ymax=max_cihi, colour="naive"),
                  width=0) +
    geom_point(aes(y=naive, colour="naive"),
               size = 2) +
    facet_wrap(~ outcome,nrow=1) +
    scale_x_discrete(labels = unique(score_code_hard_fx$bin)) + 
    xlab("Relative Slant of News Consumption (Hard News Only)") +
    ylab("Average Treatment Effect\nof Fox vs. MSNBC") +
    scale_y_continuous(breaks=seq(-0.2,0.2,0.1),
                       labels=plot_labels()$att,
                       limits = c(-0.235, 0.235),
                       sec.axis = dup_axis(name="",
                                           breaks=seq(-0.2,0.2,0.1),
                                           labels = plot_labels()$share)) +
    scale_colour_manual(values=c(naive="black", bounds=red_mit),
                        guide="none") + 
    theme(axis.text.x = element_text(size = 10, angle = 0, hjust = 0.5, color = "black")))

ggsave(j2_b, path = plot_path, filename = "fig_j2_b.pdf", 
       width=9, height = 5, dpi = 600)

# > Figure J3: Effects by stated preferences ----

# Construct labels for plotting
med_pref_labs <- paste0("Prefer\n", c("MSNBC", "Entertainment", "Fox"))

# Treatment effects with CIs for stated preferences
stated_fx <- map(1:3, function(x){
  fox_plot(var = "med_pref_num", pref_val = x, labels = med_pref_labs)
}) %>% bind_rows()

(j3 <- ggplot(na.omit(stated_fx), aes(x= factor(val), colour=result)) +
    geom_hline(yintercept=0, col = "white") +
    geom_hline(yintercept=0, linetype="dashed", col = grey_dark) +
    geom_errorbar(aes(ymin=min_cilo90, ymax=max_cihi90, colour="naive"),
                  width=0, lwd = 1) +
    geom_errorbar(aes(ymin=min_cilo, ymax=max_cihi, colour="naive"),
                  width=0) +
    geom_point(aes(y=naive, colour="naive"),
               size = 2) +
    facet_wrap(~ outcome,nrow=1) +
    xlab("Stated Media Preference") +
    ylab("Average Treatment Effect\nof Fox vs. MSNBC") +
    scale_y_continuous(breaks=seq(-0.2,0.2,0.1),
                       labels=plot_labels()$att,
                       limits = c(-0.235, 0.235),
                       sec.axis = dup_axis(name="",
                                           breaks=seq(-0.2,0.2,0.1),
                                           labels = plot_labels()$share)) +
    scale_x_discrete(labels=med_pref_labs) + 
    scale_colour_manual(values=c(naive="black", bounds=red_mit),
                        guide="none") + 
    theme(axis.text.x = element_text(size = 10, angle = 0, hjust = 0.5, color = "black")))

ggsave(j3, path = plot_path, filename = "fig_j3.pdf", 
       width=9, height=4.75, dpi = 600)

# Appendix K: Regression Tables ----

# > Regression tables for main results ----

# Tables K1-K4 generate regression tables corresponding to Figures 3-5 in the 
# main manuscript. In all cases, we calculate the naive difference in means and
# estimate standard errors and confidence intervals using robust standard errors
# (HC2) variant.

# Table K1: relative volume results
consump_labels_table <- c("\\multirow{2}{2.25cm}{\\centering{Low News Consumption}}",
                          "\\multirow{2}{2.25cm}{\\centering{Medium News Consumption}}",
                          "\\multirow{2}{2.25cm}{\\centering{High News Consumption}}")
vsent_reg_table(var = "news_consump_bin3", nbins = 3, labels = consump_labels_table,
                out_name = "/consump_bin3_table", 
                caption = "OLS Models by Relative Volume")

# Table K2: relative slant results (all URLs)  
code_labels_table <- c("\\multirow{2}{2.25cm}{\\centering{More Liberal Than CNN}}",
                       "\\multirow{2}{2.25cm}{\\centering{Between CNN and Yahoo!}}",
                       "\\multirow{2}{2.25cm}{\\centering{More Conserv. Than Yahoo!}}")
vsent_reg_table(var = "score_code", nbins = 3, labels = code_labels_table,
                out_name = "/score_code_table", 
                caption = "OLS Models by Relative Slant (All URLs)")

# Table K3: relative slant results (hard news URLs only)
vsent_reg_table(var = "score_code_hard", nbins = 3, labels = code_labels_table,
                out_name = "/score_code_hard_table", 
                caption = "OLS Models by Relative Slant (Hard News Only)")

# Table K4: stated preference results
pref_labels_table <- c("\\multirow{2}{2.25cm}{\\centering{Prefer MSNBC}}",
                       "\\multirow{2}{2.25cm}{\\centering{Prefer Entertainment}}",
                       "\\multirow{2}{2.25cm}{\\centering{Prefer\\\\Fox}}")
vsent_reg_table(var = "med_pref_num", nbins = 3, labels = pref_labels_table,
                out_name = "/med_pref_table", 
                caption = "OLS Models by Stated Media Preferences")

# > Regression tables with controls ----

# Tables K5-K8 replicate the above regression models but also control for several
# demographic variables, including age (continuous), gender, race, education, partisanship,
# ideology, and attention to national news. Coefficients for these control variables are
# omitted from the tables, due to space concerns. Age and attention to national news are
# both standardized.

# Table K5: relative volume results (with controls)
vsent_reg_table(var = "news_consump_bin3", nbins = 3, labels = consump_labels_table,
                out_name = "/consump_bin3_cont_table", controls = TRUE, 
                caption = "OLS Models by Relative Volume")

# Table K6: relative slant results (all URLs, with controls)
vsent_reg_table(var = "score_code", nbins = 3, labels = code_labels_table,
                out_name = "/score_code_cont_table", controls = TRUE,
                caption = "OLS Models by Relative Slant (All URLs)")

# Table K7: relative slant results (hard news only, with controls)
vsent_reg_table(var = "score_code_hard", nbins = 3, labels = code_labels_table,
                out_name = "/score_hard_cont_table", controls = TRUE,
                caption = "OLS Models by Relative Slant (Hard News Only)")

# Table K8: stated preference results (with controls)
vsent_reg_table(var = "med_pref_num", nbins = 3, labels = pref_labels_table,
                out_name = "/med_pref_cont_table", controls = TRUE,
                caption = "OLS Models by Stated Media Preferences")

# > Interactive models ----

srvy$article_forced <- factor(srvy$article_forced, levels = c("Entertainment",
                                                              "Fox", "MSNBC"))

# Tables K9-K12 interact the treatment indicator (assignment to partisan media vs. 
# entertainment) with a categorical indicator of respondents' revealed and stated
# preferences. For the revealed volume measure, the reference category for the latter
# variable is the lowest consumption of news vs. non-news. For the revealed slant measures,
# the reference category is the most liberal media diets (more liberal than CNN). For 
# stated preferences, the reference category is entertainment.

# Table K9: revealed volume results
consump_intx <- lm(charter_index ~ article_forced * factor(news_consump_bin3), 
                   data = srvy %>% filter(forcedchoice == 1))
consump_intx_beh <- lm(actions_index ~ article_forced * factor(news_consump_bin3), 
                       data = srvy %>% filter(forcedchoice == 1))

consump_out <- list(consump_intx, consump_intx_beh)

stargazer(consump_out, se = starprep(consump_out), p = starprep(consump_out, stat = "p.value"),
          digits=2, no.space = TRUE,
          column.sep.width = "-10pt", header = FALSE,
          font.size = "footnotesize", style = "apsr",
          table.layout ="=dc-t-s=n",
          dep.var.labels = c("\\textbf{Attitudinal Index}", "\\textbf{Sharing Index}"),
          covariate.labels = c("Fox", "MSNBC", "Medium News Consumption", "High News Consumption",
                               "Fox $\\times$ Medium News Consumption", "MSNBC $\\times$ Medium News Consumption", 
                               "Fox $\\times$ High News Consumption", "MSNBC $\\times$ High News Consumption"), 
          label = "consump_intx", title = "Difference in Treatment Effects by Relative Volume", 
          notes.append = TRUE,
          notes = c("\\textit{Note}: The reference category is Entertainment for media exposure and", 
                    "Low News Consumption for revealed volume preferences. Both dependent variables", 
                    "range from 0 to 1. \\textit{p} values are based on robust standard errors (HC2 variant)."),
          df = F, omit.stat=c("f", "ser"), model.numbers = FALSE,
          out = paste0(table_path, "/tab_k9.tex"))

# Table K10: revealed slant results (all URLs)
code_intx <- lm(charter_index ~ article_forced * factor(score_code), 
                data = srvy %>% filter(forcedchoice == 1))
code_intx_beh <- lm(actions_index ~ article_forced * factor(score_code), 
                    data = srvy %>% filter(forcedchoice == 1))

code_out <- list(code_intx, code_intx_beh)

stargazer(code_out, se = starprep(code_out), p = starprep(code_out, stat = "p.value"),
          digits=2, no.space = TRUE,
          column.sep.width = "-10pt", header = FALSE,
          font.size = "footnotesize", style = "apsr",
          table.layout ="=dc-t-s=n",
          dep.var.labels = c("\\textbf{Attitudinal Index}", "\\textbf{Sharing Index}"),
          covariate.labels = c("Fox", "MSNBC", "Between CNN and Yahoo!", "More Conserv. Than Yahoo!",
                               "Fox $\\times$ Between CNN and Yahoo!", "MSNBC $\\times$ Between CNN and Yahoo!", 
                               "Fox $\\times$ More Conserv. Than Yahoo!", "MSNBC $\\times$ More Conserv. Than Yahoo!"), 
          label = "code_intx", title = "Difference in Treatment Effects by Relative Slant (All URLs)", 
          notes.append = TRUE,
          notes = c("\\textit{Note}: The reference category is Entertainment for media exposure and More", 
                    "Liberal than CNN for revealed slant preferences. Both dependent variables", 
                    "range from 0 to 1. \\textit{p} values are based on robust standard errors (HC2 variant)."),
          df = F, omit.stat=c("f", "ser"), model.numbers = FALSE,
          out = paste0(table_path, "/tab_k10.tex"))

# Table K11: revealed slant results (hard news only)
hard_intx <- lm(charter_index ~ article_forced * factor(score_code_hard), 
                data = srvy %>% filter(forcedchoice == 1))
hard_intx_beh <- lm(actions_index ~ article_forced * factor(score_code_hard), 
                    data = srvy %>% filter(forcedchoice == 1))

hard_out <- list(hard_intx, hard_intx_beh)

stargazer(hard_out, se = starprep(hard_out), p = starprep(hard_out, stat = "p.value"),
          digits=2, no.space = TRUE,
          column.sep.width = "-10pt", header = FALSE,
          font.size = "footnotesize", style = "apsr",
          table.layout ="=dc-t-s=n",
          dep.var.labels = c("\\textbf{Attitudinal Index}", "\\textbf{Sharing Index}"),
          covariate.labels = c("Fox", "MSNBC", "Between CNN and Yahoo!", "More Conserv. Than Yahoo!",
                               "Fox $\\times$ Between CNN and Yahoo!", "MSNBC $\\times$ Between CNN and Yahoo!", 
                               "Fox $\\times$ More Conserv. Than Yahoo!", "MSNBC $\\times$ More Conserv. Than Yahoo!"), 
          label = "hard_intx", title = "Difference in Treatment Effects by Relative Slant (Hard News Only)", 
          notes.append = TRUE,
          notes = c("\\textit{Note}: The reference category is Entertainment for media exposure and More", 
                    "Liberal than CNN for revealed slant preferences. Both dependent variables", 
                    "range from 0 to 1. \\textit{p} values are based on robust standard errors (HC2 variant).",
                    "The revealed preference measure solely draws on ``hard news'' URLs."),
          df = F, omit.stat=c("f", "ser"), model.numbers = FALSE,
          out = paste0(table_path, "/tab_k11.tex"))

# Table K12: stated preference results
pref_intx <- lm(charter_index ~ article_forced * med_pref, 
                data = srvy %>% filter(forcedchoice == 1))
pref_intx_beh <- lm(actions_index ~ article_forced * med_pref, 
                    data = srvy %>% filter(forcedchoice == 1))

pref_out <- list(pref_intx, pref_intx_beh)

stargazer(pref_out, se = starprep(pref_out), p = starprep(pref_out, stat = "p.value"),
          digits=2, no.space = TRUE,
          column.sep.width = "-10pt", header = FALSE,
          font.size = "footnotesize", style = "apsr",
          table.layout ="=dc-t-s=n",
          dep.var.labels = c("\\textbf{Attitudinal Index}", "\\textbf{Sharing Index}"),
          covariate.labels = c("Fox", "MSNBC", "Prefer Fox", "Prefer MSNBC",
                               "Fox $\\times$ Prefer Fox", "MSNBC $\\times$ Prefer Fox", 
                               "Fox $\\times$ Prefer MSNBC", "MSNBC $\\times$ Prefer MSNBC"), 
          label = "pref_intx", title = "Difference in Treatment Effects by Stated Media Preferences", 
          notes.append = TRUE,
          notes = c("\\textit{Note}: The reference category is Entertainment for media exposure and Prefer", 
                    "Entertainment for stated media preferences. Both dependent variables", 
                    "range from 0 to 1. \\textit{p} values are based on robust standard errors (HC2 variant)."),
          df = F, omit.stat=c("f", "ser"), model.numbers = FALSE,
          out = paste0(table_path, "/tab_k12.tex"))

# > Comparing Fox vs. MSNBC ----

# Tables K13-K20 re-estimate these models but instead just compare respondents
# assigned to Fox or MSNBC, excluding respondents assigned to entertainment. Tables
# K13-K16 estimate the naive difference in means, and Tables K17-K20 incorporate the
# same control covariates as above.

# Table K13: revealed volume results
foxmsnbc_reg_table(var = "news_consump_bin3", nbins = 3, labels = consump_labels_table,
                   out_name = "/consump_bin3_table_fox", 
                   caption = "OLS Models for Fox vs. MSNBC by Relative Volume")

# Table K14: revealed slant results (all URLs)
foxmsnbc_reg_table(var = "score_code", nbins = 3, labels = code_labels_table,
                   out_name = "/score_code_table_fox", 
                   caption = "OLS Models for Fox vs. MSNBC by Relative Slant (All URLs)")

# Table K15: revealed slant results (hard news only)
foxmsnbc_reg_table(var = "score_code_hard", nbins = 3, labels = code_labels_table,
                   out_name = "/score_hard_table_fox", 
                   caption = "OLS Models for Fox vs. MSNBC by Relative Slant (Hard News Only)")

# Table K16: stated preference results
foxmsnbc_reg_table(var = "med_pref_num", nbins = 3, labels = pref_labels_table,
                   out_name = "/med_pref_table_fox",
                   caption = "OLS Models for Fox vs. MSNBC by Stated Media Preferences")

# Table K17: revealed volume results (with controls)
foxmsnbc_reg_table(var = "news_consump_bin3", nbins = 3, labels = consump_labels_table,
                   out_name = "/consump_bin3_table_fox_cont", controls = T,
                   caption = "OLS Models for Fox vs. MSNBC by Relative Volume")

# Table K18: revealed slant results (all URLs, with controls)
foxmsnbc_reg_table(var = "score_code", nbins = 3, labels = code_labels_table,
                   out_name = "/score_code_table_fox_cont", controls = T,
                   caption = "OLS Models for Fox vs. MSNBC by Relative Slant (All URLs)")

# Table K19: revealed slant results (with controls, hard news only)
foxmsnbc_reg_table(var = "score_code_hard", nbins = 3, labels = code_labels_table,
                   out_name = "/score_hard_table_fox_cont", controls = T,
                   caption = "OLS Models for Fox vs. MSNBC by Relative Slant (Hard News Only)")

# Table K20: stated preference results (with controls)
foxmsnbc_reg_table(var = "med_pref_num", nbins = 3, labels = pref_labels_table,
                   out_name = "/med_pref_table_fox_cont", controls = T,
                   caption = "OLS Models for Fox vs. MSNBC by Stated Media Preferences")
